﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace DevWeb.Biztalk.DeploymentSettings.Data.CodeFirst.Configurations
{
    public class IntegrationVersionConfiguration : EntityTypeConfiguration<IntegrationVersion>
    {

        public IntegrationVersionConfiguration()
        {
            ToTable("IntegrationVersion");

            Property(p => p.Description).HasMaxLength(500);
            Property(p => p.CreateDateTime).IsRequired();
            Property(p => p.Version).IsRequired().IsConcurrencyToken();
            Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            HasKey(p => p.Id);
            HasRequired(p => p.Integration);
            Property(p => p.ProductId).IsRequired();
            Ignore(p => p.IntegrationName);
            Ignore(p => p.ProductUpgradeCode);
           // Ignore(p => p.IntegrationId);

            HasMany(p => p.IntegrationVersionParameters)
                .WithRequired(i => i.IntegrationVersion)
                .HasForeignKey(i => i.IntegrationVersionId);
            HasMany(p => p.DeploymentLogs)
                .WithRequired(d => d.IntegrationVersion)
                .HasForeignKey(d => d.IntegrationVersionId);

           HasRequired(p => p.Integration).WithMany(i => i.IntegrationVersions).HasForeignKey(p => p.IntegrationId);


        }
    }
}
